#!/bin/sh
# SPDX-License-Identifier: LicenseRef-MSLA
# Copyright (c) 2017-2024 Silicon Laboratories Inc. (www.silabs.com)
#
# The licensor of this software is Silicon Laboratories Inc. Your use of this
# software is governed by the terms of the Silicon Labs Master Software License
# Agreement (MSLA) available at [1].  This software is distributed to you in
# Object Code format and/or Source Code format and is governed by the sections
# of the MSLA applicable to Object Code, Source Code and Modified Open Source
# Code. By using this software, you agree to the terms of the MSLA.
#
# [1]: https://www.silabs.com/about-us/legal/master-software-license-agreement

SRC_DIR=$1
VERSION_FILE=$2
GIT_LABEL="$(git -C $SRC_DIR describe --tags --dirty --match "*v[0-9]*" || echo '<unknown version>')"

cat << EOF > $VERSION_FILE.tmp
/* SPDX-License-Identifier: LicenseRef-MSLA */
/* THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT! */
#include <stdint.h>
#include "common/version.h"

/*
 * wsbrd API versions:
 *
 * 2.0.0
 * - Complete API change
 * 0.2.0
 * - Pop the retry_per_rate array and the successful phy mode id
 *   in SPINEL_CMD_PROP_IS/SPINEL_PROP_STREAM_STATUS that were
 *   used to send the data, necessary for mode switch fallback
 * 0.1.0
 * - Pop ACK request, frame pending, and PAN ID suppression in
 *   PROP_IS/STREAM_RAW, for MAC frame reconstruction
 */

const char *version_daemon_str = "${GIT_LABEL}";
uint32_t version_daemon_api = VERSION(2, 0, 0);
EOF

if cmp -s $VERSION_FILE $VERSION_FILE.tmp
then
    rm -f $VERSION_FILE.tmp
else
    mv -f $VERSION_FILE.tmp  $VERSION_FILE
fi
